package com.socialweb.dao;

import com.socialweb.domain.UserData;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class UserDataDAOImpl implements UserDataDAO{

    @Autowired
    private SessionFactory sessionFactory;
    
    @Override
    public UserData findById(int id) {
        return (UserData)sessionFactory.getCurrentSession().getNamedQuery("UserData.findById").
                setParameter("user_id", id).uniqueResult();
    }

    @Override
    public void updateAll(UserData userData) {
        sessionFactory.getCurrentSession().update(userData);
//        return sessionFactory.getCurrentSession().getNamedQuery("UserData.updateAll").
//                setParameter("name", userData.getName()).
//                setParameter("surname", userData.getSurname()).
//                setParameter("hobby", userData.getHobby()).
//                setParameter("birth", userData.getBirth()).
//                setParameter("email", userData.getEmail()).
//                setParameter("phone", userData.getPhone()).
//                setParameter("id", userData.getId()).executeUpdate();
    }
    
}
